// 工具列表功能初始化
document.addEventListener('DOMContentLoaded', function() {
  // 分类筛选功能
  document.querySelectorAll('.category-badge').forEach(btn => {
    btn.addEventListener('click', function() {
      const category = this.dataset.category;
      const toolItems = document.querySelectorAll('.tool-item');
      const favorites = JSON.parse(localStorage.getItem('toolFavorites') || '[]');

      toolItems.forEach(item => {
        const toolId = item.querySelector('.favorite-btn').dataset.toolId;
        if (category === 'all' || 
            item.dataset.categories.includes(category) || 
            (category === 'common' && favorites.includes(toolId))) {
          item.style.display = 'block';
        } else {
          item.style.display = 'none';
        }
      });

      // 更新按钮状态
      document.querySelectorAll('.category-badge').forEach(btn => btn.classList.remove('active'));
      this.classList.add('active');
      document.getElementById('tool-search').value = '';
    });
  });


  // 搜索功能
  const searchInput = document.getElementById('tool-search');
  searchInput.addEventListener('input', function() {
    const searchTerm = this.value.toLowerCase();
    const toolItems = document.querySelectorAll('.tool-item');

    toolItems.forEach(item => {
      const toolName = item.querySelector('.card-title').textContent.toLowerCase();
      const toolDesc = item.querySelector('.card-text').textContent.toLowerCase();

      if (toolName.includes(searchTerm) || toolDesc.includes(searchTerm)) {
        item.style.display = 'block';
      } else {
        item.style.display = 'none';
      }
    });
  });
});